<template>
	<view class="manage-times">
		<view class="mt-item">
			<text>开始时间：</text>
			<view class="select-time">
				<picker mode="time" :value="storeMsg.workstarttime" :start="startTime" :end="endTime" @change="onTime1">
					<view>{{storeMsg.workstarttime}}</view>
				</picker>
			</view>
		</view>
		<view class="mt-item">
			<text>结束时间：</text>
			<view class="select-time">
				<picker mode="time" :value="storeMsg.workendtime" :start="startTime" :end="endTime" @change="onTime2">
					<view>{{storeMsg.workendtime}}</view>
				</picker>
			</view>
		</view>
		<view class="describe">
			填写准确的营业时间可以更好的提升顾客的体验度！
		</view>
		<button class="button" type="primary" @click="onConfirm">确认</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				startTime: '00:00', // 选中的开始时间
				endTime: '24:00', // 选中的结束时间
				time1: '09:00', 
				time2: '18:00',
				storeMsg: {},
			}
		},
		onShow() {
			this.storeMsg = uni.getStorageSync('lph-storeInfo');
		},
		methods: {
			onTime1(e) {
				this.storeMsg.workstarttime = e.target.value;
				uni.setStorageSync('lph-storeInfo',this.storeMsg);
			},
			onTime2(e) {
				this.storeMsg.workendtime = e.target.value;
				uni.setStorageSync('lph-storeInfo',this.storeMsg);
			},
			async onConfirm() {
				let a = {
					workstarttime: this.storeMsg.workstarttime,
					workendtime: this.storeMsg.workendtime
				}
				let b = await this.$http.setShopManageTime(a);
				console.log(b);
				if (b.code == 200) {
					uni.showToast({
						title: b.message,
						icon: 'none'
					})
					uni.setStorageSync('lph-storeInfo',a.data);
					setTimeout(() => {
						uni.navigateBack({})
					}, 500)
					return
				}
				uni.showToast({
					title: b.message,
					icon: 'none'
				})

			},
		}

	}
</script>

<style lang="scss" scoped>
	@import 'static/css/myStore.scss';
</style>
